--  gatenode操作：

local skynet = require "skynet"
local cluster = require "skynet.cluster"
require "skynet.manager"

local filelog = require "filelog"
local configdao = require "configdao"

local function check()
	local chk = require("run_check")
	if not chk then
		print("check config failed!")
		skynet.abort()
	end
end
skynet.start(function()
	-- check()
	skynet.newservice("nodelog")
	local confsharesvr = skynet.newservice("confshare")
	skynet.call(confsharesvr, "lua", "start")

	local pbcservice = skynet.uniqueservice("pbcservice")
	-- local protofilename = {"primary", "ddz", "mjzz"}
	-- skynet.call(pbcservice, "lua", "init", "../", protofilename)
	skynet.call(pbcservice, "lua", "initproto", "../proto/primary.proto")

	skynet.call(pbcservice, "lua", "initproto", "../psznode/psz.proto")
	skynet.call(pbcservice, "lua", "initproto", "../dnnode/dn.proto")
	skynet.call(pbcservice, "lua", "initproto", "../ddznode/ddz.proto")
	skynet.call(pbcservice, "lua", "initproto", "../brnnnode/brnn.proto")
	skynet.call(pbcservice, "lua", "initproto", "../lhdnode/lhd.proto")
	skynet.call(pbcservice, "lua", "initproto", "../rbnode/rb.proto")
    skynet.call(pbcservice, "lua", "initproto", "../ttznode/ttz.proto")
    skynet.call(pbcservice, "lua", "initproto", "../hbslnode/hbsl.proto")
	skynet.call(pbcservice, "lua", "initproto", "../bjlnode/bjl.proto")
	skynet.call(pbcservice, "lua", "initproto", "../bmnode/bm.proto")
	skynet.call(pbcservice, "lua", "initproto", "../lhjnode/lhj.proto")
	skynet.call(pbcservice, "lua", "initproto", "../fqzsnode/fqzs.proto")
	skynet.call(pbcservice, "lua", "initproto", "../sgjnode/sgj.proto")
	skynet.call(pbcservice, "lua", "initproto", "../yydbnode/yydb.proto")
	skynet.call(pbcservice, "lua", "initproto", "../slwhnode/slwh.proto")
	skynet.call(pbcservice, "lua", "initproto", "../imnode/im.proto")
	skynet.call(pbcservice, "lua", "initproto", "../fishnode/fish.proto")
	skynet.call(pbcservice, "lua", "initproto", "../dicenode/dice.proto")
	skynet.call(pbcservice, "lua", "initproto", "../cpcqsscnode/cpcqssc.proto")
	skynet.call(pbcservice, "lua", "initproto", "../lpnode/lp.proto")
	skynet.call(pbcservice, "lua", "initproto", "../mjexnode/mjex.proto")
	skynet.call(pbcservice, "lua", "initproto", "../ernnnode/ernn.proto")
	skynet.call(pbcservice, "lua", "initproto", "../dice3node/dice3.proto")
	skynet.call(pbcservice, "lua", "initproto", "../zrbjlnode/zrbjl.proto")
	skynet.call(pbcservice, "lua", "initproto", "../zrlhdnode/zrlhd.proto")
	skynet.call(pbcservice, "lua", "initproto", "../zrttznode/zrttz.proto")
	skynet.call(pbcservice, "lua", "initproto", "../zrbrnnnode/zrbrnn.proto")
	skynet.call(pbcservice, "lua", "initproto", "../zrdice3node/zrdice3.proto")
	skynet.call(pbcservice, "lua", "initproto", "../sssnode/sss.proto")
	skynet.call(pbcservice, "lua", "initproto", "../pjnode/pj.proto")
	skynet.call(pbcservice, "lua", "initproto", "../lhdanode/lhda.proto")
	
	local gatenode = configdao.get_cfgsvrs_key("gatenode")
	skynet.newservice("debug_console",gatenode.debug_console_port)

	skynet.name(".nodeuuid", skynet.uniqueservice("nodeuuid") )
	-- print("line46", skynet.call(".nodeuuid", "lua", "getuuid"))

    -- 需要连接到gm的redis， 主要是为了给后台push消息
	skynet.name(".gmmqredis", skynet.newservice("redisdb"))	
	skynet.call(".gmmqredis", "lua", "init", configdao.get_cfgsvrs_key("gmmqredis"))

	skynet.name(".router", skynet.uniqueservice("router") )	
	skynet.call(".router", "lua", "get_rank")
    skynet.call(".router", "lua", "get_clientver")
    skynet.call(".router", "lua", "get_massmail")
	skynet.call(".router", "lua", "get_paychannel")
	skynet.name(".offlinerole", skynet.uniqueservice("offlinerole")) -- 离线玩家数据处理
    skynet.name(".fangkalog", skynet.newservice("datalog"))     -- 房卡数据日志
	skynet.call(".fangkalog", "lua", "init", "fangka")         -- applog/fangka检查目录是否存在
    skynet.name(".coinlog", skynet.newservice("datalog"))     -- 金豆数据日志
	skynet.call(".coinlog", "lua", "init", "coin")         -- applog/coin检查目录是否存在
	skynet.name(".diamondlog", skynet.newservice("datalog"))     -- 钻石数据日志处
	skynet.call(".diamondlog", "lua", "init", "diamond")         -- applog/diamond检查目录是否存在
	skynet.name(".gamedatalog", skynet.newservice("datalog"))    -- 游戏数据日志处
    skynet.call(".gamedatalog", "lua", "init", "gamedata")			-- applog/game检查目录是否存在
    skynet.name(".maillog", skynet.newservice("datalog"))       -- 邮件日志
    skynet.call(".maillog", "lua", "init", "maildata")			-- applog/maildata检查目录是否存在
	skynet.name(".gameresult", skynet.uniqueservice("gameresult"))	-- 战绩处理
	skynet.name(".mailbox", skynet.uniqueservice("mailbox"))		-- 邮件处理
	skynet.name(".knapsack", skynet.uniqueservice("knapsack"))		-- 背包处理
	skynet.name(".givesystem", skynet.uniqueservice("givesystem"))  -- 赠送系统
	skynet.name(".roletablestate", skynet.uniqueservice("roletablestate"))	
	skynet.call(".roletablestate", "lua", "restore")

	skynet.name(".horseracelamp", skynet.uniqueservice("horseracelamp"))	
	skynet.name(".hallad", skynet.uniqueservice("hallad"))	
	skynet.call(".hallad", "lua", "init")
	-- 同时打开两个节点
	cluster.open("gatenode")
	cluster.open("hallnode")

	local watchdog = skynet.newservice("gatenode")
	skynet.call(watchdog, "lua", "cmd", "start", {
		port = gatenode.svr_port,
		maxclient = gatenode.maxclient or 10000,
		nodelay = true,
		agentsize = gatenode.agentsize or 500,
		agentincr = gatenode.agentincr or 100,
	})
	skynet.name(".mainnode", watchdog)
	skynet.exit()
end)
